<?php

if(!defined("INDEX"))
    die;
    
if($user->id == 0) {
    header('Location: /login');
    exit;
}

// ----------------------------------------------------------------------------

try {

    if(!empty($_FILES['file']['name'])) {

        $user->uploadPicture($_FILES['file']);
    }

    $new_lang = obtainHTTPVar('lang', null);

    if($new_lang) {
        if($new_lang != $user->lang) {
            switch($new_lang) {
                case 'en':
                case 'ru':
                    $user->lang = $new_lang;
                    $user->select_lang = true;
                    $user->save();
                    break;

            }
            header('Location: /settings');
            exit;
        }
    }

    $smarty->assign('userpic_max_width', USERPICS_THUMB_WIDTH);
    $smarty->assign('userpic_max_height', USERPICS_THUMB_HEIGHT);

} catch (CoreException $e) {

    throw new CoreException($e->getMessage());

} catch (Exception $e) {

    $smarty->assign('errors', array($e->getMessage()));
}